#include <iostream>
using namespace std;

int main()
{
    cout << "hello" << endl;

    string s = "abcdefg";
    char &a = s[2];
    char &b = s[3];

    a = '1';
    b = '2';

    cout << s << endl;
    cout << (int *)s.c_str() << endl;

    s = "pppppppppppppppppppppppp";

    //a = '1';
    //b = '2';

    cout << s << endl;
    cout << (int *)s.c_str() << endl;

    //string和c-style字符串转换
    //string 转 char*
    string str = "str";
    const char *cstr = str.c_str();
    cout << cstr << endl;
    //char* 转String
    char *char_s = "char* to string";
    string str2(s);
    cout << char_s << endl;
    //总结
    //Char*是一个指针，String是一个类
    //string封装了char*，管理这个字符串，是一个char*型的容器。
    //string类当中封装了查找find，拷贝copy，删除delete 替换replace，插入insert
    //string类不用考虑内存释放和越界
    string str3 = "+= test";
    string str4;
    str4 += str3;
    cout << str4 << endl;
    //替换从pos开始n个字符为字符串str
    string str5 = str4.replace(0, 1, "t");
    //剪切字符
    string str6 = str5.substr(1, str5.length());
    cout << str6 << endl;

    system("pause");
    return 0;
}